package com.atguigu.juc.chap09;

public class VolatileDemo {

    private volatile static Integer flag = 1;

    public static void main(String[] args) throws InterruptedException {

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("子线程工作内存读取到的flag的值：" + flag);
                while (flag == 1) {

                }
                System.out.println("子线程工作内存读取到的flag的最新的值..." + flag);
            }
        }).start();

        Thread.sleep(500);

        flag = 2; // 主线程修改flag的值
        System.out.println("我是主线程工作内存flag的值：" + flag);
    }
}